<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>拆分 HTML</title>
</head>
<body>
<div id="output"></div>
<script>
    var html = '<h2>Hello World!</h2>' +
            '<p>We love JavaScript!</p>';
    var regex = /<[^>\r\n]+>|[^<>\r\n]+/g;
    var results = html.match(regex);
    document.getElementById('output').innerText = results.join('\r\n');
</script>
</body>
</html>